<template>
	<view class="personList_con">
		<view class="top_con">
			<view class="title">选择就诊人</view>
			<view class="remark">
				<image src="/static/images/title_icon.png"></image>
				档案信息严格保密，仅您自己可见</view>
		</view>
		<view class="grop_con">
			<view v-for="(item,index) in dataList" :key="index" class="guid">
				<view class="left">
					<view class="img"></view>
					<view class="info">
						<view class="up"><text style="display:inline-block;width:100rpx">{{item.name}}</text> <span>{{getRelationship(item.relationship)}}</span></view>
						<view class="center">{{item.gender==="M"?"男":"女"}} {{item.age}}岁</view>
						<!-- <view class="text">有病例</view> -->
					</view>
				</view>
				<view class="icon" v-if="item.isDefault == 1">
					<image src="/static/images/radio.png" style="width:100%;height:100%"></image>
				</view>
				<view v-else class="noIcon"></view>
			</view>
		</view>
		<view class="add_con" @click="add()">
			<view class="icon">
				<image src="/static/images/add.png" style="width:100%;height:100%"></image>
			</view>
			<view class="">新增患者档案档案</view>
		</view>
		<view class="btn_con">
			<span @click="cancal()">确定</span>
		</view>
	</view>
</template>

<script>
	import { patientList } from "@/api/consultation";
	import { relationshipDict } from "@/pages/tabbar/home/patients/personDict";
	export default{
		data(){
			return{
				dataList:[],
				selectedPatient: null,
			}
		},
		onShow() {
			console.log(relationshipDict)
			this.getPatientFun()
		},
		methods: {
			// 获取关系
			getRelationship(relationship){
				return relationshipDict[relationship].value
			},
			async getPatientFun(){
				let params = {mobile:uni.getStorageSync('userPhone')}
				let res = await patientList(params)
				console.log(res)
				if(res.code == 200){
					this.dataList = res.data
					this.selectedPatient = res.data[0]
				}
			},
			add(){
				uni.navigateTo({
					url:"/pages/tabbar/home/patients/add"
				})
			},
			cancal(){
				// 关闭当前页面，返回上一页,并保存选中的患者
				uni.setStorageSync('selectedPatient', this.selectedPatient);
				uni.navigateBack({
					delta: 1
				})
			}	
		}
	}
</script>

<style lang="scss" scoped>
	.personList_con{
		width:100%;
		height:100%;
		background: #F8F8F8;
		padding: 22rpx 30rpx 80rpx 30rpx;
		font-family: PingFang SC, PingFang SC;
		.top_con{
			margin-bottom: 30rpx;
			padding: 10rpx 0;
			.title{
				font-weight: 600;
				font-size: 32rpx;
				color: #000000;
				margin-bottom: 9rpx;
			}
			.remark{
				display: flex;
				align-items: center;
				font-weight: 400;
				font-size: 26rpx;
				color: #999999;
				image{
					width:26rpx;
					height:31rpx;
					margin-right: 12rpx;
				}
				
			}
		}
		.grop_con{
			.guid{
				background: #fff;
				margin-bottom: 21rpx;
				border-radius: 8rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 37rpx 46rpx;
				.left{
					display: flex;
					.img{
						width:119rpx;
						height:120rpx;
						margin-right: 30rpx;
						border:1rpx solid #ddd;
						border-radius: 50%;
					}
					.info{
						.up{
							font-weight: 600;
							font-size: 32rpx;
							color: #000000;
							span{
								margin-left: 39rpx;
								background: #FFF1F2;
								border-radius: 5rpx;
								padding: 8rpx 16rpx;
								font-weight: 400;
								font-size: 26rpx;
								color: #7D2527;
							}
						}
						.center{
							font-weight: 400;
							font-size: 30rpx;
							color: #666666;
						}
						.text{
							font-weight: 400;
							font-size: 30rpx;
							color: #666666;
						}
					}
				}
				.icon{
					width:47rpx;
					height:47rpx;
				}
				.noIcon{
					width:47rpx;
					height:47rpx;
					border-radius: 47rpx;
					border:1rpx solid #666666;
				}
			}
		}
		.add_con{
			background: #fff;
			margin-bottom: 21rpx;
			border-radius: 8rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			padding: 37rpx 46rpx;
			font-weight: 600;
			font-size: 32rpx;
			color: #000000;
			.icon{
				width:77rpx;
				height:79rpx;
				margin-right: 40rpx;
			}
		}
		.btn_con{
			position: fixed;
			bottom: 40rpx;
			padding: 0 29rpx;
			width:100%;
			left: 0;
			span{
				display: inline-block;
				width:100%;
				background: #7D2527;
				border-radius: 50rpx;
				height:80rpx;
				line-height: 80rpx;
				text-align: center;
				font-size: 32rpx;
				color:#fff;
			}
		}
	}
</style>